package com.cskaoyan.service.wx;

import com.cskaoyan.bean.FootPriceList;
import com.cskaoyan.bean.FootPrint;
import com.cskaoyan.bean.FootPrintVO;
import com.cskaoyan.bean.User;
import com.cskaoyan.mapper.FootPrintMapper;
import com.cskaoyan.mapper.UserMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author pengyehua
 * @date 2020/12/9 10:57
 */
@Service
public class WxFootprintServiceImpl implements WxFootprintService{

    @Autowired
    FootPrintMapper footPrintMapper;

    @Autowired
    UserMapper userMapper;

    /**
     * 查询足迹
     * @param page
     * @param size
     * @return
     */
    @Override
    public FootPriceList queryFootprint(int page, int size,String name) {
        User user = userMapper.selectUserByName(name);
        //分页
        PageHelper.startPage(page,size);

        List<FootPrintVO> footprintList = footPrintMapper.selectFootprintAndGoods(user.getId());

        FootPriceList footPriceList = new FootPriceList();
        footPriceList.setFootprintList(footprintList);
        //获取总条目数
        PageInfo<FootPrintVO> pageInfo = new PageInfo<>(footprintList);
        long total = pageInfo.getTotal();
        footPriceList.setTotalPages((int)total);
        return footPriceList;
    }

    /**
     * 删除足迹
     * @param ids
     */
    @Override
    public void deleteFootprint(Integer id) {
        FootPrint footPrint = new FootPrint();
        footPrint.setId(id);
        footPrint.setDeleted(true);
        footPrintMapper.updateByPrimaryKeySelective(footPrint);
    }
}
